package com.yang.controller;

import com.yang.entity.Commodity;
import com.yang.entity.PageBean;
import com.yang.entity.Result;
import com.yang.service.CommodityService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/commodity")
public class CommodityController {

    @Resource
    private CommodityService commodityService;

    /**
     * 获取商品列表，支持模糊查找
     * @param pageNum 当前页
     * @param pageSize 每页数量
     * @param commodityName
     * @return
     */
    @GetMapping("/list")
    public Result<PageBean<Commodity>> getCommodityList(
        Integer pageNum,
        Integer pageSize,
        @RequestParam(required = false) String commodityName
    ) {
        System.out.println("getCommodityList =====>");
        System.out.println(commodityName);
        PageBean<Commodity> pageBean = commodityService.getCommodityList(pageNum, pageSize, commodityName);
        return Result.success(pageBean);
    }

}
